﻿#define _CRT_SECURE_NO_WARNINGS 

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<pair<int, int>> activities(n);
    for (int i = 0; i < n; ++i) {
        cin >> activities[i].second >> activities[i].first;
        // 读取时反转顺序，方便后续按结束时间排序
    }

    sort(activities.begin(), activities.end());  // 按 bᵢ 排序

    int count = 0;
    int lastEnd = 0;

    for (auto& activity : activities) {
        if (activity.second >= lastEnd) {
            ++count;
            lastEnd = activity.first;
        }
    }

    cout << count << endl;
    return 0;
}


/////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<pair<int, int>> activities(n);
    for (int i = 0; i < n; ++i) {
        cin >> activities[i].second >> activities[i].first;
        // 读取时反转顺序，方便后续按结束时间排序
    }

    sort(activities.begin(), activities.end());  // 按 bᵢ 排序

    int count = 0;
    int lastEnd = 0;

    for (auto& activity : activities) {
        if (activity.second >= lastEnd) {
            ++count;
            lastEnd = activity.first;
        }
    }

    cout << count << endl;
    return 0;
}



////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, k, d;
    cin >> n >> k >> d;
    vector<long long> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    // dp_max[i][j]：选j个数，以第i个结尾的最大值
    vector<vector<long long>> dp_max(n + 1, vector<long long>(k + 1, -0x3f3f3f3f));
    vector<vector<long long>> dp_min(n + 1, vector<long long>(k + 1, 0x3f3f3f3f));

    // 初始化：选1个数
    for (int i = 1; i <= n; ++i) {
        dp_max[i][1] = dp_min[i][1] = a[i];
    }

    // 状态转移
    for (int j = 2; j <= k; ++j) {
        for (int i = 1; i <= n; ++i) {
            for (int p = max(1, i - d); p < i; ++p) {
                dp_max[i][j] = max(dp_max[i][j], max(dp_max[p][j - 1] * a[i], dp_min[p][j - 1] * a[i]));
                dp_min[i][j] = min(dp_min[i][j], min(dp_max[p][j - 1] * a[i], dp_min[p][j - 1] * a[i]));
            }
        }
    }

    // 从所有 dp_max[i][k] 中找最大值
    long long result = -0x3f3f3f3f;
    for (int i = 1; i <= n; ++i) {
        result = max(result, dp_max[i][k]);
    }

    cout << result << endl;
    return 0;
}
